/**
 * 	Copyright (c) 2011 Cody's Studio
 *
 *	All rights reserved
 *
 *  Create By cody on 2011-7-26 下午11:25:25
 */
package com.dboper.helper;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

/**
 * @Title 数据库工具辅助类 
 * @author cody 2011-7-26 Create
 * @version 1.0
 */
public class DbHelper {
	/**
	 * @Title 获取数据库所有字段类型
	 * @author cody 2011-7-27 Create
	 * @param dbType
	 * @return
	 */
	public static List<String> getTypeList(String dbType) {
    	List<String> list = new ArrayList<String>();
    	SAXReader saxReader = new SAXReader();
    	String path = DbHelper.class.getClassLoader().getResource("com/dboper/constant/colType.xml").getPath();
    	File file = new File(path);
    	try {
			Document doc = saxReader.read(file);
			@SuppressWarnings("unchecked")
			List<Element> eles = doc.selectNodes("//root/dbtype[@name='"+dbType+"']/type");
			if(eles != null && eles.size() != 0) {
				for(Element ele : eles){
					list.add(ele.attributeValue("value"));
				}
			}
		} catch (DocumentException e) {
			e.printStackTrace();
		}
    	return list;
    }
	
	public static void main(String args[]) {
		List<String> list = DbHelper.getTypeList("MySQL");
		for(String str : list) {
			System.out.println(str);
		}
	}
}
